using UnityEngine;

public class SaleUI : MonoBehaviour
{
	private GameObject uiobj;

	public UIEventListener buybtn;

	public UIEventListener closebtn;

	public Animator animator;
	//public Animation scaleanima;

	public UILabel timelabel;

	private bool isshow;

	private void Start()
	{
		buybtn.onClick = OnClickbuyBtn;
		closebtn.onClick = OnClickcloseBtn;
	}

	private void Update()
	{
		timelabel.text = MyMath.longtimeset(MainUI.caltime);
	}

	public void OnClickbuyBtn(GameObject btn)
	{
		MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
		if (MenuPlayerprefs.instance.saleid == 0)
		{
			Platform.Billing(12);
		}
		else if (MenuPlayerprefs.instance.saleid == 2)
		{
			Platform.Billing(13);
		}
		else
		{
			Platform.ToastShort("You've already bought it!");
		}
	}

	public void init_ui_info()
	{
		if (!isshow)
		{
			isshow = true;
			//scaleanima.Stop();
			animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
			Invoke("animplay", Time.deltaTime * 2f);
		}
	}

	public void animplay()
	{
		/* scaleanima["PopWinAnimation"].time = 0f;
		scaleanima["PopWinAnimation"].speed = 1f;
		scaleanima.Play(); */
		animator.SetTrigger("popWin1");
	}

	public void enable()
	{
		if (uiobj == null)
		{
			uiobj = base.gameObject;
		}
		init_ui_info();
		NGUITools.SetActive(uiobj, state: true);
	}

	public void OnClickcloseBtn(GameObject btn)
	{
		if (isshow)
		{
			isshow = false;
			if (btn != null)
			{
				MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
			}
			/* scaleanima["PopWinAnimation"].time = scaleanima.clip.length;
			scaleanima["PopWinAnimation"].speed = -1f;
			scaleanima.Play(); */
			animator.SetTrigger("popWin2");
			Invoke("disable", animator.runtimeAnimatorController.animationClips[0].length);
		}
	}

	public void disable()
	{
		isshow = false;
		MenuBackController.instance.BackMenuUIstate();
		NGUITools.SetActive(uiobj, state: false);
	}
}
